﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LeanCloud;
using System;
using UnityEngine.UI;

public class NewClick : MonoBehaviour {

    public InputField ShopIDInPut;
    string shop_id;             //朔源码
    string shop_name;           //产品名称
    string shop_Firstnum;       //防伪码前缀
    string shop_num;            //防伪码
    string shop_batching;       //配料
    string shop_weight;         //净重
    DateTime shop_shengchandate;//生产日期
    DateTime shop_jiedongdate;  //解冻日期
    string shop_production;     //生产商
    string shop_address;        //地址
    string shop_shengchancode;  //生产许可编号
    string shop_guomin;         //过敏提示
    Image shop_xiangguanzizhi;  //相关资质上传
    Image shop_ErWeima;         //二维码

    string material_supplyname; //供应商名称
    string material_supplyzizhi;//供应商资质
    string material_picicode;   //批次号
    string material_shengchanaddress; //生产地址
    DateTime material_shengchandate;  //生产日期

    DateTime logistics_indate;      //入库时间
    DateTime logistics_outdate;     //出库时间
    string logistics_information;   //物流信息 object[]
    string logistics_companyname;   //物流公司名称
    string logistics_car;           //车辆信息 object
    string logistics_driver;        //驾驶员信息 object


    //public static string objectId;//返回的唯一码

    // Use this for initialization
    void Start () {

    }
	
	// Update is called once per frame
	void Update ()
    {
    }

    
    public void OverButton()
    {
        shop_id = ShopIDInPut.text;
        shop_name = Input_name.name;
        shop_Firstnum = Input_Firstnum.Fnum;
        shop_num = Input_num.num;
        shop_batching = Input_batching.peilaio;
        shop_weight = Input_weight.weight;
        shop_production = Input_production.production;
        shop_address = Input_address.address;
        shop_shengchancode = Input_shengchancode.shengchancode;
        shop_guomin = Input_guomin.guomin;
        //shop_ErWeima = transform.Find(RawImage);
        material_supplyname = Input_GYSname.name;
        material_picicode = Input_picicode.picicode;
        material_shengchanaddress = Input_shengchanaddress.shengchanaddress;
        material_shengchandate = Input_shengchandate.dateTime;
        logistics_indate = Input_indate.indate;
        logistics_outdate = Input_outdate.outdate;
        logistics_information = Input_information.information;
        logistics_companyname = Input_companyname.companyname;
        logistics_car = Input_car.car;
        logistics_driver = Input_driver.driver;

        //shop_xiangguanzizhi = Input_xiangguanzizhi.xiangguanzizhi;

        //Debug.Log("shop_idXXX:" + shop_id);
        //Debug.Log("Input_id.id:" + Input_id.id);

        Async();
        
    }

    async System.Threading.Tasks.Task Async()
    {
        AVClient.Initialize("bKNobM2wmMsD7ReQ1f2Py91W-gzGzoHsz", "zudIgpWooM5QChpsT4E1yAAY", "https://bknobm2w.lc-cn-n1-shared.com");
        AVClient.HttpLog(Debug.Log);

        //增加一行
        //List<AVObject> objects = new List<AVObject>();
        //行中项为
        var wuliuDictionar = new Dictionary<string, string>();
        wuliuDictionar.Add("time", "time1");
        wuliuDictionar.Add("address", "address1");
        


        var equipBag = new AVObject("GameEquipBag")
        {
            //["shop_id"] = shop_id,
            ["shop_id"] = ShopIDInPut.text,
            ["shop_name"] = shop_name,
            ["shop_Firstnum"] = shop_Firstnum,
            ["shop_num"] = shop_num,
            ["shop_batching"] = shop_batching,
            ["shop_weight"] = shop_weight,
            ["shop_production"] = shop_production,
            ["shop_address"] = shop_address,
            ["shop_shengchancode"] = shop_shengchancode,
            ["shop_guomin"] = shop_guomin,
            ["material_supplyname"] = material_supplyname,
            ["material_picicode"] = material_picicode,
            ["material_shengchanaddress"] = material_shengchanaddress,
            ["material_shengchandate"] = material_shengchandate,
            ["logistics_indate"] = logistics_indate,
            ["logistics_outdate"] = logistics_outdate,
            
            ["logistics_information"] = logistics_information,
            ["logistics_companyname"] = logistics_companyname,
            ["logistics_car"] = logistics_car,
            ["logistics_driver"] = logistics_driver
        };

        await equipBag.SaveAsync();
        //objectId = equipBag.ObjectId;//（返回的唯一码）
        Debug.Log(equipBag.ObjectId);


        byte[] data = System.Text.Encoding.UTF8.GetBytes("Hi LeanCloud");
        AVFile file = new AVFile("RwaImage.png", data, new Dictionary<string, object>(){
            {"二维码","LeanCloud"}
        });
        //file["shop_ErWeima"] = shop_ErWeima;

        await file.SaveAsync();
        Debug.Log(file.ObjectId);
    }
}
